package com.program.facesigninsystem.service.impl;

import com.program.facesigninsystem.dao.IFriendDao;
import com.program.facesigninsystem.service.IRedisService;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * @author sxw
 */
@Slf4j
@Component
@Async
public class ScheduledService {
    private final static Logger logger = LoggerFactory.getLogger(ScheduledService.class);
    private IFriendDao iFriendDao;
    private IRedisService iRedisService;

    @Autowired
    public ScheduledService(IFriendDao iFriendDao, IRedisService iRedisService) {
        this.iFriendDao = iFriendDao;
        this.iRedisService = iRedisService;
    }

    //每隔1小时执行一次
    @Scheduled(cron = "0 0 */10 * * ?")
    public void scheduled(){
        try {
            List<Map<String,Object>> rank=iFriendDao.overallRanking();
            iRedisService.addRank(rank);
            logger.info("获取总排名");
        }catch (Exception e) {
            logger.error(String.valueOf(e));
        }
    }
}
